<?php

class Session
{
    public static function Run()
    {
        define('SESSION_PREFIX', Sys::$conf['SESSION_PREFIX']);
        if (isset($_SERVER['HTTP_X_TOKEN'])) {
            $SID = $_SERVER['HTTP_X_TOKEN'];
            session_id($SID);
        }
        session_start();
    }
    public static function Set($key, $value)
    {
        isset($_SESSION[SESSION_PREFIX]) || $_SESSION[SESSION_PREFIX] = [];
        $_SESSION[SESSION_PREFIX][$key]                               = $value;
    }
    public static function SetArray($array)
    {
        $_SESSION[SESSION_PREFIX] = $array;
    }
    public static function Get($key, $default = null)
    {
        return self::Is($key) ? $_SESSION[SESSION_PREFIX][$key] : $default;
    }
    public static function Is($key, $value = false)
    {
        if ($value) {
            return (isset($_SESSION[SESSION_PREFIX][$key]) && $_SESSION[SESSION_PREFIX][$key] == $value);
        } else {
            return (isset($_SESSION[SESSION_PREFIX][$key]) && $_SESSION[SESSION_PREFIX][$key] !== false);
        }
    }
    public static function Clear()
    {
        session_unset($_SESSION[SESSION_PREFIX]);
    }
}
